package com.service.order;

import com.common.ErrorCodeEnum;
import com.common.exception.BusinessException;
import com.common.utils.StringUtils;
import com.core.springSecurity.common.SecurityUtils;
import com.dao.order.OrderTaskInfoMapper;
import com.github.pagehelper.PageHelper;
import com.model.domain.order.GetOrderTaskInfoDO;
import com.model.pojo.order.OrderTaskInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * @Author: zql
 * @Description: 任务订单记录服务
 * @Data: 2023-10-22
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderTaskInfoService {

    private final  OrderTaskInfoMapper orderTaskInfoMapper;

    /**
     * @Author: zql
     * @Description: 创建任务订单记录
     * @param orderTaskInfo 被创建对象主体
     * @Data: 2023-10-22
     */
    public void create(OrderTaskInfo orderTaskInfo) {
        String name = SecurityUtils.getUsername();
        orderTaskInfo.setCreatedTime(null);
        orderTaskInfoMapper.insertSelective(orderTaskInfo);
    }

    /**
     * @Author: zql
     * @Description: 创建任务订单记录列表
     * @param orderTaskInfoList 增加的对象主体列表
     * @Data: 2023-10-22
     */
    public void createList(List<OrderTaskInfo> orderTaskInfoList) {
        String name = SecurityUtils.getUsername();
        orderTaskInfoList.forEach(o -> {
            o.setCreatedTime(null);
        });
        orderTaskInfoMapper.insertListSelective(orderTaskInfoList);
    }

    /**
     * @Author: zql
     * @Description: 更新任务订单记录信息
     * @param orderTaskInfo 更新的对象主体内容
     * @Data: 2023-10-22
     */
    public void update(OrderTaskInfo orderTaskInfo) {
        String name = SecurityUtils.getUsername();
        orderTaskInfo.setCreatedTime(null);
        orderTaskInfoMapper.updateByPrimaryKeySelective(orderTaskInfo);
    }

    /**
     * @Author: zql
     * @Description: 更新任务订单记录列表信息
     * @param orderTaskInfoList 更新的对象主体内容列表
     * @Data: 2023-10-22
     */
    public void updateList(List<OrderTaskInfo> orderTaskInfoList) {
        String name = SecurityUtils.getUsername();
        orderTaskInfoList.forEach(o -> {
            o.setCreatedTime(null);
        });
        orderTaskInfoMapper.updateListSelective(orderTaskInfoList);
    }



    /**
     * @Author: zql
     * @Description: 查看任务订单记录列表
     * @param getOrderTaskInfoDO 查询条件
     * @Data: 15:02 2021/6/3
     */
    public List<OrderTaskInfo> getList(GetOrderTaskInfoDO getOrderTaskInfoDO) {
        PageHelper.clearPage();
        PageHelper.startPage(getOrderTaskInfoDO.getPage(), getOrderTaskInfoDO.getPageSize(), getOrderTaskInfoDO.getSortRow() + getOrderTaskInfoDO.getSortOrder());
        return orderTaskInfoMapper.selectList(getOrderTaskInfoDO);
    }
    public List<OrderTaskInfo> getALL(GetOrderTaskInfoDO getOrderTaskInfoDO) {
        return orderTaskInfoMapper.selectList(getOrderTaskInfoDO);
    }
    /**
     * @Author: zql
     * @Description: 查看任务订单记录
     * @param orderTaskInfoId 任务订单记录Id
     * @Data: 2023-10-22
     */
    public OrderTaskInfo get(Long orderTaskInfoId, Byte isDelete) {
        OrderTaskInfo orderTaskInfo = orderTaskInfoMapper.selectByPrimaryKey(orderTaskInfoId);
        if (StringUtils.isNull(orderTaskInfo)) {
            throw new BusinessException(ErrorCodeEnum.DATA_NOT_FOUNT);
        }
        return orderTaskInfo;
    }

}
